package com.android.phpclient;


import com.utez.sistemas.sam.R;

import Clases.AlumnoDatos;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class Menu_Alumno extends Activity implements OnClickListener{

	
	TextView alumno,carrera,matricula;
	String alumnoA,carreraA,matriculaA;
	
	Button verCalif;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.menu__alumno);
		
		
		alumno=(TextView) findViewById(R.id.Alumno);
        carrera=(TextView) findViewById(R.id.Carrera);
        matricula=(TextView) findViewById(R.id.MatriculaAlum);
        
        Bundle bundle=getIntent().getExtras();
    String  id=bundle.getString("id");
        
        ServerAccess ss=new ServerAccess();
        
        AlumnoDatos[] AlumnoA=ss.DatosAlumno(id);	
        
        AlumnoD alumnoss=new AlumnoD(this,R.layout.datos_alumno, AlumnoA);
        
        

        for(int i=0;i<alumnoss.array.length;i++){
        	alumnoA=""+alumnoss.array[i].alumno;
        	matriculaA=""+alumnoss.array[i].matricula;
        	carreraA=""+alumnoss.array[i].nombre;
        }
        
        alumno.setText("Alumno: "+alumnoA);
        carrera.setText("Carrera: "+carreraA);
  matricula.setText("Matricula: "+matriculaA);
  
  
  verCalif=(Button) findViewById(R.id.btCalif);
  verCalif.setOnClickListener(this);
  
  
	}

	 private class AlumnoD extends ArrayAdapter<AlumnoDatos>
		{
			
			
			//Array to have the objects
			private AlumnoDatos[] array;
			
			public AlumnoD(Context context, int textViewResourceId,AlumnoDatos[] objects) {
				super(context, textViewResourceId,objects);
				array=objects;
			}
			
			@Override
			public View getView(int position, View convertView, ViewGroup parent) {
				//Set the view for each item in the list view
				View v = convertView;
	            if (v == null) {
	                LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	                v = vi.inflate(R.layout.datos_alumno, null);
	            }
	            //Get the Textviews from the row view and set the appropriate values for them
	            TextView alumno=(TextView) v.findViewById(R.id.alumno);
	            TextView matricula=(TextView) v.findViewById(R.id.matricula);
	            TextView carrera=(TextView) v.findViewById(R.id.carrera);
	            
	            alumno.setText(array[position].alumno);
	            matricula.setText(array[position].matricula);
	            carrera.setText(array[position].nombre);
	            
	            
				return v;
			}
		}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		if(v.getId()==R.id.btCalif){
			Intent i=new Intent(this,Alumno.class);
		
			
			Bundle bundle = new Bundle();
			bundle.putString("id",matriculaA);
			
			i.putExtras(bundle);
		
			
			
	startActivity(i);
		}
	}


}
